home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_MacPaint / Source / shared.subproj / RCS / ResultObject.m,v < prev    next >
Text File  |  1995-06-12  |  38KB  |  983 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  beta10:1.3;
  5. locks    death:1.4;
  6. comment  @@;
  7.  
  8.  
  9. 1.4
  10. date     93.04.04.23.45.10;  author death;  state Exp;
  11. branches ;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     93.01.10.15.08.44;  author death;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     92.07.26.13.59.14;  author death;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     92.04.27.20.51.22;  author death;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @A base class to use instead of Object, providing error results storage and
  32. multiple values for returning.
  33. @
  34.  
  35.  
  36. 1.4
  37. log
  38. @Sun Apr  4 23:45:09 PDT 1993
  39. @
  40. text
  41. @/*
  42. ====================================================================
  43. This is the implementation file for the ResultObject class.  Full documentation for this class can be found in the ResultObject.rtf file.  I will not duplicate all that fine information here.
  44.     This is $Revision: 1.3 $ of this file
  45.     It was last modified by $Author: death $ on $Date: 93/01/10 15:08:44 $
  46. Note that this file was created while using the New Century Schoolbook Roman typeface.  You may find that some things line up strangely if you don't use that family.
  47. $Log:    ResultObject.m,v $
  48. Revision 1.3  93/01/10  15:08:44  death
  49. Sun Jan 10 15:08:44 PST 1993
  50.  
  51. Revision 1.2  92/07/26  13:59:14  death
  52. Update of the result object...
  53.  
  54. ====================================================================
  55. */
  56.  
  57. //
  58. //    Import our own definition
  59. //
  60. #import "ResultObject.h"
  61. #import <strings.h>
  62. #import <stdlib.h>
  63. #import <memory.h>
  64.  
  65. @@implementation ResultObject
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  73. //    Routine:        CopyCString:
  74. //    Parameters:    a string that we want to copy and store
  75. //    Returns:        self
  76. //    Description:
  77. //        Stores the specified string in the first storage area for returned data.  The
  78. //        string is copied first.
  79. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  80. - (Instance) CopyCString: (CString) data
  81. {
  82.     return [self CopyCString: data Into: FIRST_RESULT];
  83. }
  84.  
  85. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  86. //    Routine:        CopyCString:Into:
  87. //    Parameters:    a string, and location to store it
  88. //    Returns:        self
  89. //    Description:
  90. //        Attempts to make a copy of the string.  If we succeed, we store it in the requested
  91. //        position, otherwise, we do nothing but post an error!!!.
  92. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  93. - (Instance) CopyCString: (CString) data Into: (Integer) reference
  94. {
  95.     GenericType    theData;
  96.     Integer    status;
  97.     CString    tempStr;
  98.     
  99.     tempStr = (char*) malloc(strlen(data)+1);
  100.     if (tempStr == NullCString)
  101.         status = ERR_CANTSTORE;
  102.     else
  103.     {
  104.         strcpy(tempStr, data);
  105.         theData.cstring = tempStr;
  106.         [self PutData: theData WithType: TYPE_CSTRING  Into: reference DoIOwn: YES];
  107.         status = [self GetMyError];
  108.         if (status != ERR_OK)
  109.             free(tempStr);
  110.     }
  111.     [self StoreMyError: status];
  112.     return self;
  113. }
  114.  
  115. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  116. //    Routine:        CopyPointer:WithLength:
  117. //    Parameters:    a pointer, and the length of its data
  118. //    Returns:        self
  119. //    Description:
  120. //        Stores the specified data in the first storage area.  Copies the data that the
  121. //        pointer points to, first..
  122. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  123. - (Instance) CopyPointer: (Pointer) data WithLength: (PositiveInteger) length 
  124. {
  125.     return [self CopyPointer: data WithLength: length Into: FIRST_RESULT];
  126. }
  127.  
  128. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  129. //    Routine:        CopyPointer:WithLength:Into:
  130. //    Parameters:    data item, and location to store it
  131. //    Returns:        self
  132. //    Description:
  133. //        Stores the specified data in the specified storage area.  To do this, we build
  134. //    a data type with our data and its type, and then we ask to store it properly.
  135. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  136. - (Instance) CopyPointer: (Pointer) data WithLength: (PositiveInteger) length Into: (Integer) reference
  137. {
  138.     GenericType    theData;
  139.     Integer    status;
  140.     Pointer    tempPtr;
  141.     
  142.     tempPtr = (Pointer) malloc(length);
  143.     if (tempPtr == NullPointer)
  144.         status = ERR_CANTSTORE;
  145.     else
  146.     {
  147.         bcopy(data, tempPtr, length);
  148.         theData.pointer = tempPtr;
  149.         [self PutData: theData WithType: TYPE_POINTER  Into: reference DoIOwn: YES];
  150.         status = [self GetMyError];
  151.         if (status != ERR_OK)
  152.             free(tempPtr);
  153.     }
  154.     [self StoreMyError: status];
  155.     return self;
  156. }
  157.  
  158.  
  159. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  160. //    Routine:        init
  161. //    Parameters:    none
  162. //    Returns:        self
  163. //    Description:
  164. //        This initalizes this object.  What this means is simply that we call the parent
  165. //        to init, and then clear all our storage areas
  166. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  167. - (Instance) init
  168. {
  169.     Integer    index;
  170.     StorageArea*    SA;    // pointer to the storage area we want to work on.
  171.  
  172.     [super init];
  173.     //
  174.     //    Now, clear our storage areas.  We can't use ResetResults, because if there is
  175.     //    junk somewhere in there, it might try to free some string or ptr that doesn't exist...
  176.     //
  177.     for (index = 0; index < MAXAREAS; index++)
  178.     {
  179.         SA = &ReturnVals[index];    // Esentially doing a pascal WITH ReturnVals[index]...
  180.         SA->StoredData.type = TYPE_NONE;
  181.         SA->StoredData.data.integer = 0;
  182.         SA->IOwnData = NO;
  183.     }
  184.     return self;
  185. }
  186.  
  187.  
  188. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  189. //    Routine:        free
  190. //    Parameters:    none
  191. //    Returns:        self
  192. //    Description:
  193. //        Clears anything about us, then asks the parent to clear themselves too...
  194. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  195. - free
  196. {
  197.     [self ResetResults];
  198.     [super free];
  199.     return self;
  200. }
  201.  
  202.  
  203. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  204. //    Routine:        GetBoolean
  205. //    Parameters:    none
  206. //    Returns:        a boolean value
  207. //    Description:
  208. //        Retrieves the boolean value, if any, from the first storage area, and returns it.
  209. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  210. - (Boolean) GetBoolean
  211. {
  212.     return [self GetBooleanFrom: FIRST_RESULT];
  213. }
  214.  
  215. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  216. //    Routine:        GetBooleanFrom:
  217. //    Parameters:    an integer indicating which storage area to retrieve from
  218. //    Returns:        a Boolean value
  219. //    Description:
  220. //        Retrieves the boolean value, if any, from the storage area specified.
  221. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  222. - (Boolean) GetBooleanFrom: (Integer) reference
  223. {
  224.     GenericType data;
  225.     
  226.     data = [self GetDataWithType: TYPE_BOOLEAN From: reference];
  227.     if ([self GetMyError] == ERR_OK)
  228.         return data.boolean;
  229.         else return NO;
  230. }
  231.  
  232. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  233. //    Routine:        GetCharacter
  234. //    Parameters:    none
  235. //    Returns:        a character value
  236. //    Description:
  237. //        Retrieves the character value, if any, from the first storage area, and returns it.
  238. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  239. - (Character) GetCharacter
  240. {
  241.     return [self GetCharacterFrom: FIRST_RESULT];
  242. }
  243.  
  244.  
  245. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  246. //    Routine:        GetCharacterFrom:
  247. //    Parameters:    an integer indicating which storage area to retrieve from
  248. //    Returns:        a character value
  249. //    Description:
  250. //        Retrieves the character value, if any, from the storage area specified.
  251. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  252. - (Character) GetCharacterFrom: (Integer) reference
  253. {
  254.     GenericType data;
  255.     
  256.     data = [self GetDataWithType: TYPE_CHARACTER From: reference];
  257.     if ([self GetMyError] == ERR_OK)
  258.         return data.character;
  259.         else return (Character) 0;
  260. }
  261.  
  262. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  263. //    Routine:        GetCString
  264. //    Parameters:    none
  265. //    Returns:        a Cstring value
  266. //    Description:
  267. //        Retrieves the cstring value, if any, from the first storage area, and returns it.
  268. //        This assumes that GetCString has already made a copy of the data to return
  269. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  270. - (CString) GetCString
  271. {
  272.     return [self GetCStringFrom: FIRST_RESULT];
  273. }
  274.  
  275.  
  276. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  277. //    Routine:        GetCStringFrom
  278. //    Parameters:    a number indicating which storage area to retrieve from
  279. //    Returns:        a Cstring value
  280. //    Description:
  281. //        Retrieves the cstring value, if any, from the specified storage area, and returns it.
  282. //        We always make a copy of the string and then return the copy.
  283. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  284. - (CString) GetCStringFrom: (Integer) reference
  285. {
  286.     GenericType data;
  287.     CString tempStr = NullCString;
  288.     
  289.     data = [self GetDataWithType: TYPE_CSTRING From: reference];
  290.     if ([self GetMyError] == ERR_OK)
  291.     {
  292.         tempStr = (CString) malloc(strlen(data.cstring)+1);
  293.         if (tempStr == NullCString)
  294.         {
  295.             [self StoreMyError: ERR_CANTSTORE];
  296.             free(tempStr);
  297.             tempStr = NullCString;
  298.         }
  299.         else
  300.             strcpy(tempStr, data.cstring);
  301.     }
  302.     return tempStr;
  303. }
  304.  
  305.  
  306. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  307. //    Routine:        GetDataWithType:From:
  308. //    Parameters:    none
  309. //    Returns:        a generic type value
  310. //    Description:
  311. //        Locates a data value in the storage area specified by storage.  If it matches
  312. //        the requested type, return it.  Otherwise, post an error.
  313. //        At present, we ignore the owning flag...
  314. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  315. - (GenericType) GetDataWithType: (Integer) theType From: (Integer) storage;
  316. {
  317.     Integer status;
  318.     GenericType theData;
  319.     
  320.     if ((storage > MAXAREAS -1) || (storage < 0))
  321.         status = ERR_NOSUCHAREA;
  322.     else
  323.     {
  324.         if (ReturnVals[storage].StoredData.type != theType)
  325.         {
  326.             status = ERR_NOSUCHTYPE;
  327.             theData.integer = 0;
  328.         }
  329.         else
  330.         {
  331.             theData = ReturnVals[storage].StoredData.data;
  332.             status = ERR_OK;
  333.         }
  334.     }
  335.     [self StoreMyError: status];
  336.     return theData;
  337. }
  338.  
  339.  
  340. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  341. //    Routine:        GetErrorCode
  342. //    Parameters:    none
  343. //    Returns:        an integer value
  344. //    Description:
  345. //        Retrieves an error code from the main error code storage area.
  346. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  347. - (Integer) GetErrorCode
  348. {
  349.     return [self GetIntegerFrom: ERRORCODE_RESULT];
  350. }
  351.  
  352.  
  353. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  354. //    Routine:        GetErrorText
  355. //    Parameters:    none
  356. //    Returns:        a CString value
  357. //    Description:
  358. //        Retrieves a string from the error string result area, and returns it to the
  359. //        caller.  Note that this does mean it retrieves and returns a copy..
  360. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  361. - (CString) GetErrorText
  362. {
  363.     return [self GetCStringFrom: ERRORTEXT_RESULT];
  364. }
  365.  
  366.  
  367. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  368. //    Routine:        GetInteger
  369. //    Parameters:    none
  370. //    Returns:        an integer value
  371. //    Description:
  372. //        Retrieves the integer value, if any, from the first storage area.
  373. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  374. - (Integer) GetInteger
  375. {
  376.     return [self GetIntegerFrom: FIRST_RESULT];
  377. }
  378.  
  379.  
  380. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  381. //    Routine:        GetIntegerFrom:
  382. //    Parameters:    an integer indicating which storage area to retrieve from
  383. //    Returns:        a Boolean value
  384. //    Description:
  385. //        Retrieves the boolean value, if any, from the storage area specified.
  386. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  387. - (Integer) GetIntegerFrom: (Integer) reference
  388. {
  389.     GenericType data;
  390.     
  391.     data = [self GetDataWithType: TYPE_INTEGER From: reference];
  392.     if ([self GetMyError] == ERR_OK)
  393.         return data.integer;
  394.         else return 0;
  395. }
  396.  
  397.  
  398. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  399. //    Routine:        GetMyError
  400. //    Parameters:    none
  401. //    Returns:        an error value
  402. //    Description:
  403. //        Retrieves the error code that the methods that make up this class will
  404. //        generate, in case they had any problems while working.  At the moment, only
  405. //        GetDataWithType:From:  and PutDataWithType: Into:DoIOwn: store error
  406. //        codes..  oh, and so do the two Copy methods..
  407. //        Note that we must access the info directly, and not call GetData, otherwise
  408. //        we'll be mutually recursing for a brief time before we crash.
  409. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  410. - (Integer) GetMyError
  411. {    
  412.     return ReturnVals[MYERROR_RESULT].StoredData.data.integer;
  413. }
  414.  
  415.  
  416. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  417. //    Routine:        GetObject
  418. //    Parameters:    none
  419. //    Returns:        an Object value
  420. //    Description:
  421. //        Retrieves the Object value, if any, from the first storage area.
  422. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  423. - (Instance) GetObject
  424. {
  425.     return [self GetObjectFrom: FIRST_RESULT];
  426. }
  427.  
  428. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  429. //    Routine:        GetObjectFrom:
  430. //    Parameters:    a reference to the storagearea we want to retrieve the value from
  431. //    Returns:        an Object value
  432. //    Description:
  433. //        Retrieves the Object value, if any, from the specified storage area
  434. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  435. - (Instance) GetObjectFrom: (Integer) reference
  436. {
  437.     GenericType data;
  438.     
  439.     data = [self GetDataWithType: TYPE_INSTANCE From: reference];
  440.     if ([self GetMyError] == ERR_OK)
  441.         return data.instance;
  442.         else return 0;
  443. }
  444.  
  445.  
  446. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  447. //    Routine:        GetPointer
  448. //    Parameters:    none
  449. //    Returns:        a pointer value
  450. //    Description:
  451. //        Retrieves the pointer value, if any, from the first storage area.  It does NOT
  452. //        make a copy of the pointer data.
  453. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  454. - (Pointer) GetPointer
  455. {
  456.     return [self GetPointerFrom: FIRST_RESULT];
  457. }
  458.  
  459.  
  460. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  461. //    Routine:        GetPointerFrom:
  462. //    Parameters:    an integer indicating what storage area to retrieve from
  463. //    Returns:        a pointer value
  464. //    Description:
  465. //        Retrieves the pointer value, if any, from the specified storage are.  It does NOT
  466. //        make a copy of the pointer data.
  467. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  468. - (Pointer) GetPointerFrom: (Integer) reference
  469. {
  470.     GenericType data;
  471.     
  472.     data = [self GetDataWithType: TYPE_POINTER From: reference];
  473.     if ([self GetMyError] == ERR_OK)
  474.         return data.pointer;
  475.         else return NullPointer;
  476. }
  477.  
  478.  
  479. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  480. //    Routine:        GetPositiveInteger
  481. //    Parameters:    none
  482. //    Returns:        a positive integer value
  483. //    Description:
  484. //        Retrieves the positiveinteger value, if any, from the first storage area.
  485. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  486. - (PositiveInteger) GetPositiveInteger
  487. {
  488.     return [self GetPositiveIntegerFrom: FIRST_RESULT];
  489. }
  490.  
  491.  
  492. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  493. //    Routine:        GetPositiveIntegerFrom:
  494. //    Parameters:    an integer indicating which storage area to retrieve from
  495. //    Returns:        a PositiveInteger value
  496. //    Description:
  497. //        Retrieves the integer value, if any, from the storage area specified.
  498. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  499. - (PositiveInteger) GetPositiveIntegerFrom: (PositiveInteger) reference
  500. {
  501.     GenericType data;
  502.     
  503.     data = [self GetDataWithType: TYPE_POSITIVEINTEGER From: reference];
  504.     if ([self GetMyError] == ERR_OK)
  505.         return data.positiveinteger;
  506.         else return 0;
  507. }
  508.  
  509.  
  510. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  511. //    Routine:        PutBoolean:Into:
  512. //    Parameters:    data item, and location to store it
  513. //    Returns:        self
  514. //    Description:
  515. //        Stores the specified data in the specified storage area.  To do this, we build
  516. //    a data type with our data and its type, and then we ask to store it properly.
  517. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  518. - (Instance) PutBoolean: (Boolean) data Into: (Integer) reference
  519. {
  520.     GenericType    theData;
  521.  
  522.     theData.boolean = data;
  523.     [self PutData: theData WithType: TYPE_BOOLEAN  Into: reference DoIOwn: YES];
  524.     return self;
  525. }
  526.  
  527.  
  528. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  529. //    Routine:        PutCharacter:Into:
  530. //    Parameters:    data item, and location to store it
  531. //    Returns:        self
  532. //    Description:
  533. //        Stores the specified data in the specified storage area.  To do this, we build
  534. //    a data type with our data and its type, and then we ask to store it properly.
  535. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  536. - (Instance) PutCharacter: (Character) data Into: (Integer) reference
  537. {
  538.     GenericType    theData;
  539.  
  540.     theData.character = data;
  541.     [self PutData: theData WithType: TYPE_CHARACTER  Into: reference DoIOwn: YES];
  542.     return self;
  543. }
  544.  
  545.  
  546. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  547. //    Routine:        PutCString:Into:
  548. //    Parameters:    data item, and location to store it
  549. //    Returns:        self
  550. //    Description:
  551. //        Stores the specified data in the specified storage area.  To do this, we build
  552. //    a data type with our data and its type, and then we ask to store it properly.
  553. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  554. - (Instance) PutCString: (CString) data Into: (Integer) reference
  555. {
  556.     GenericType    theData;
  557.  
  558.     theData.cstring = data;
  559.     [self PutData: theData WithType: TYPE_CSTRING  Into: reference DoIOwn: NO];
  560.     return self;
  561. }
  562.  
  563.  
  564. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  565. //    Routine:        PutData:Into:DoIOwn:
  566. //    Parameters:    data to be stored, which storage area to put it in, and whether we own it
  567. //    Returns:        self
  568. //    Description:
  569. //        If we are trying to store in an area that we shouldn't be, then return an error and
  570. //        don't store anything.  Otherwise copy our information into the storage area.
  571. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  572. - (Instance) PutData: (GenericType) theData WithType: (Integer) theType
  573.     Into: (Integer) storage DoIOwn: (Boolean) ownit
  574. {
  575.     Integer status;
  576.     
  577.     if ((storage > MAXAREAS -1) || (storage < 0))
  578.         status = ERR_NOSUCHAREA;
  579.     else
  580.     {
  581.         ReturnVals[storage].IOwnData = ownit;
  582.         ReturnVals[storage].StoredData.data= theData;
  583.         ReturnVals[storage].StoredData.type= theType;
  584.         status = ERR_OK;
  585.     }
  586.     [self StoreMyError: status];
  587.     return self;
  588. }
  589.  
  590.  
  591. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  592. //    Routine:        PutInteger:Into:
  593. //    Parameters:    data item, and location to store it
  594. //    Returns:        self
  595. //    Description:
  596. //        Stores the specified data in the specified storage area.  To do this, we build
  597. //    a data type with our data and its type, and then we ask to store it properly.
  598. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  599. - (Instance) PutInteger: (Integer) data Into: (Integer) reference
  600. {
  601.     GenericType    theData;
  602.  
  603.     theData.integer = data;
  604.      [self PutData: theData WithType: TYPE_INTEGER  Into: reference DoIOwn: YES];
  605.     return self;
  606. }
  607.  
  608.  
  609. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  610. //    Routine:        PutObject:Into:
  611. //    Parameters:    data item, and location to store it
  612. //    Returns:        self
  613. //    Description:
  614. //        Stores the specified data in the specified storage area.  To do this, we build
  615. //    a data type with our data and its type, and then we ask to store it properly.
  616. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  617. - (Instance) PutObject: (Instance) data Into: (Integer) reference
  618. {
  619.     GenericType    theData;
  620.  
  621.     theData.instance = data;
  622.     [self PutData: theData WithType: TYPE_INSTANCE  Into: reference DoIOwn: NO];
  623.     return self;
  624. }
  625.  
  626.  
  627. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  628. //    Routine:        PutPointer:Into:
  629. //    Parameters:    data item, and location to store it
  630. //    Returns:        self
  631. //    Description:
  632. //        Stores the specified data in the specified storage area.  To do this, we build
  633. //    a data type with our data and its type, and then we ask to store it properly.
  634. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  635. - (Instance) PutPointer: (Pointer) data Into: (Integer) reference
  636. {
  637.     GenericType    theData;
  638.  
  639.     theData.pointer = data;
  640.     [self PutData: theData WithType: TYPE_POINTER Into: reference DoIOwn: NO];
  641.     return self;
  642. }
  643.  
  644.  
  645. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  646. //    Routine:        PutPositiveInteger:Into:
  647. //    Parameters:    data item, and location to store it
  648. //    Returns:        self
  649. //    Description:
  650. //        Stores the specified data in the specified storage area.  To do this, we build
  651. //    a data type with our data and its type, and then we ask to store it properly.
  652. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  653. - (Instance) PutPositiveInteger: (PositiveInteger) data Into: (Integer) reference
  654. {
  655.     GenericType    theData;
  656.     
  657.     theData.positiveinteger = data;
  658.     [self PutData: theData WithType: TYPE_POSITIVEINTEGER Into: reference DoIOwn: YES];
  659.     return self;
  660. }
  661.  
  662.  
  663. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  664. //    Routine:        ResetResults
  665. //    Parameters:    none
  666. //    Returns:        self
  667. //    Description:
  668. //        This clears all the result storage areas.  This is accomplished by:
  669. //            (1) Freeing any strings or pointers we own
  670. //            (2) Setting all data items to a type of TYPE_NONE
  671. //            (3) (this is redundant) putting 0 into each storage data item
  672. //        This is accomplished by first checking if we own the data, and if so, if it is a poiner
  673. //        or a CString. If so, then we take the data, and implicitly cast it as a char* and free it.
  674. //        In any case, we then set the type of the data storage area to no data type, and clear
  675. //        the data item (again, implicitly casting the data item to do this).  This implicit
  676. //        casting can be done because the ultimate data item is a union with multiple types
  677. //        unioned in it.  =)
  678. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  679. - (Instance) ResetResults
  680. {
  681.     Integer    index;
  682.     StorageArea*    SA;    // pointer to the storage area we want to work on.
  683.     
  684.     for (index = 0; index < MAXAREAS; index++)
  685.     {
  686.         SA = &ReturnVals[index];    // Esentially doing a pascal WITH ReturnVals[index]...
  687.         if ((SA->IOwnData == YES) &&
  688.             ((SA->StoredData.type == TYPE_CSTRING) ||
  689.             (SA->StoredData.type == TYPE_POINTER)))
  690.             free(SA->StoredData.data.cstring);
  691.         SA->StoredData.type = TYPE_NONE;
  692.         SA->StoredData.data.integer = 0;
  693.         SA->IOwnData = NO;
  694.     }
  695.     //
  696.     //    Special case.  put a empty CString into the error text, to allow for sloppy
  697.     //    programming.
  698.     //
  699.     [self PutCString: "" Into: ERRORTEXT_RESULT];
  700.     return self;
  701. }
  702.  
  703.  
  704. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  705. //    Routine:        StoreErrorCode:AndText:
  706. //    Parameters:    an error code and an error string to be stored for the callser to find
  707. //    Returns:        self
  708. //    Description:
  709. //        This stores the error code and error string into the result areas reserved for
  710. //        them, and returns self.
  711. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  712. - (Instance) StoreErrorCode: (Integer) code AndText: (CString) text
  713. {
  714.     [self PutInteger: code Into: ERRORCODE_RESULT];
  715.     [self PutCString: text Into: ERRORTEXT_RESULT];
  716.     return self;
  717. }
  718.  
  719.  
  720. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  721. //    Routine:        StoreErrorCode:AndCopyOfText:
  722. //    Parameters:    an error code and an error string to be stored for the callser to find
  723. //    Returns:        self
  724. //    Description:
  725. //        This stores its the error code, and a full copy of the error text in the result
  726. //        areas reserved for these purposes..
  727. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  728. - (Instance) StoreErrorCode: (Integer) code AndCopyOfText: (CString) text
  729. {
  730.     [self PutInteger: code Into: ERRORCODE_RESULT];
  731.     [self CopyCString: text Into: ERRORTEXT_RESULT];
  732.     return self;
  733. }
  734.  
  735.  
  736. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  737. //    Routine:        StoreBoolean:
  738. //    Parameters:    a Boolean
  739. //    Returns:        self
  740. //    Description:
  741. //        This stores its data into the first result storage area, and returns self.
  742. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  743. - (Instance) StoreBoolean: (Boolean) data
  744. {
  745.     return [self PutBoolean: data Into: FIRST_RESULT];
  746. }
  747.  
  748.  
  749. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  750. //    Routine:        StoreCharacter:
  751. //    Parameters:    a Character
  752. //    Returns:        self
  753. //    Description:
  754. //        This stores its data into the first result storage area, and returns self.
  755. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  756. - (Instance) StoreCharacter: (Character) data
  757.     { return [self PutCharacter: data Into: FIRST_RESULT]; }
  758.  
  759.  
  760. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  761. //    Routine:        StoreCString:
  762. //    Parameters:    a CString
  763. //    Returns:        self
  764. //    Description:
  765. //        This stores its data into the first result storage area, and returns self.
  766. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  767. - (Instance) StoreCString: (CString) data
  768. {
  769.     return [self PutCString: data Into: FIRST_RESULT];
  770. }
  771.  
  772.  
  773. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  774. //    Routine:        StoreInteger:
  775. //    Parameters:    an Integer
  776. //    Returns:        self
  777. //    Description:
  778. //        This stores its data into the first result storage area, and returns self.
  779. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  780. - (Instance) StoreInteger: (Integer) data
  781. {
  782.     return [self PutInteger: data Into: FIRST_RESULT];
  783. }
  784.  
  785.  
  786. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  787. //    Routine:        StoreMyError:
  788. //    Parameters:    an Integer
  789. //    Returns:        self
  790. //    Description:
  791. //        This stores its data into the the error register used for our own error generation
  792. //        Note that this must do this nasty work itself, rather than using, say,
  793. //        PutInteger:Into:, cause otherwise it's very likely you'll have an infinite loop
  794. //        on your hand...  nasty
  795. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  796. - (Instance) StoreMyError: (Integer) data
  797. {
  798.     ReturnVals[MYERROR_RESULT].IOwnData = YES;
  799.     ReturnVals[MYERROR_RESULT].StoredData.data.integer= data;
  800.     ReturnVals[MYERROR_RESULT].StoredData.type= TYPE_INTEGER;
  801.     return self;
  802. }
  803.  
  804.  
  805. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  806. //    Routine:        StoreObject:
  807. //    Parameters:    an Object
  808. //    Returns:        self
  809. //    Description:
  810. //        This stores its data into the first result storage area, and returns self.
  811. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  812. - (Instance) StoreObject: (Instance) data
  813. {
  814.     return [self PutObject: data Into: FIRST_RESULT];
  815. }
  816.  
  817.  
  818. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  819. //    Routine:        StorePointer:
  820. //    Parameters:    a Pointer
  821. //    Returns:        self
  822. //    Description:
  823. //        This stores its data into the first result storage area, and returns self.
  824. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  825. - (Instance) StorePointer: (Pointer) data
  826. {
  827.     return [self PutPointer: data Into: FIRST_RESULT];
  828. }
  829.  
  830.  
  831. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  832. //    Routine:        StorePositiveInteger:
  833. //    Parameters:    a PositiveInteger
  834. //    Returns:        self
  835. //    Description:
  836. //        This stores its data into the first result storage area, and returns self.
  837. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  838. - (Instance) StorePositiveInteger: (PositiveInteger) data
  839. {
  840.     return [self PutPositiveInteger: data Into: FIRST_RESULT];
  841. }
  842. @@end
  843. @
  844.  
  845.  
  846. 1.3
  847. log
  848. @Sun Jan 10 15:08:44 PST 1993
  849. @
  850. text
  851. @d4 2
  852. a5 2
  853.     This is $Revision: 1.2 $ of this file
  854.     It was last modified by $Author: death $ on $Date: 92/07/26 13:59:14 $
  855. d8 3
  856. @
  857.  
  858.  
  859. 1.2
  860. log
  861. @Update of the result object...
  862. @
  863. text
  864. @d5 1
  865. a5 1
  866.     It was last modified by $Author: death $ on $Date: 92/03/29 12:14:23 $
  867. d7 4
  868. a10 1
  869. $Log:    Reply.m,v $
  870. d216 1
  871. a216 1
  872.         else return (Character) NULL;
  873. @
  874.  
  875.  
  876. 1.1
  877. log
  878. @Initial revision
  879. @
  880. text
  881. @d34 1
  882. a34 1
  883. - (Objekt) CopyCString: (CString) data
  884. d47 1
  885. a47 1
  886. - (Objekt) CopyCString: (CString) data Into: (Integer) reference
  887. d77 1
  888. a77 1
  889. - (Objekt) CopyPointer: (Pointer) data WithLength: (PositiveInteger) length 
  890. d90 1
  891. a90 1
  892. - (Objekt) CopyPointer: (Pointer) data WithLength: (PositiveInteger) length Into: (Integer) reference
  893. d101 1
  894. a101 1
  895.         bcmp(data, tempPtr, length);
  896. d121 1
  897. a121 1
  898. - (Objekt) init
  899. d361 2
  900. d365 2
  901. a366 2
  902. {
  903.     return [self GetIntegerFrom: MYERROR_RESULT];
  904. d377 1
  905. a377 1
  906. - (Objekt) GetObject
  907. d389 1
  908. a389 1
  909. - (Objekt) GetObjectFrom: (Integer) reference
  910. d393 1
  911. a393 1
  912.     data = [self GetDataWithType: TYPE_OBJECT From: reference];
  913. d395 1
  914. a395 1
  915.         return data.object;
  916. d472 1
  917. a472 1
  918. - (Objekt) PutBoolean: (Boolean) data Into: (Integer) reference
  919. d490 1
  920. a490 1
  921. - (Objekt) PutCharacter: (Character) data Into: (Integer) reference
  922. d508 1
  923. a508 1
  924. - (Objekt) PutCString: (CString) data Into: (Integer) reference
  925. d526 1
  926. a526 1
  927. - (Objekt) PutData: (GenericType) theData WithType: (Integer) theType
  928. d553 1
  929. a553 1
  930. - (Objekt) PutInteger: (Integer) data Into: (Integer) reference
  931. d571 1
  932. a571 1
  933. - (Objekt) PutObject: (Objekt) data Into: (Integer) reference
  934. d575 2
  935. a576 2
  936.     theData.object = data;
  937.     [self PutData: theData WithType: TYPE_OBJECT  Into: reference DoIOwn: NO];
  938. d589 1
  939. a589 1
  940. - (Objekt) PutPointer: (Pointer) data Into: (Integer) reference
  941. d607 1
  942. a607 1
  943. - (Objekt) PutPositiveInteger: (PositiveInteger) data Into: (Integer) reference
  944. d633 1
  945. a633 1
  946. - (Objekt) ResetResults
  947. d649 5
  948. d666 1
  949. a666 1
  950. - (Objekt) StoreErrorCode: (Integer) code AndText: (CString) text
  951. d682 1
  952. a682 1
  953. - (Objekt) StoreErrorCode: (Integer) code AndCopyOfText: (CString) text
  954. d697 1
  955. a697 1
  956. - (Objekt) StoreBoolean: (Boolean) data
  957. d710 1
  958. a710 1
  959. - (Objekt) StoreCharacter: (Character) data
  960. d721 1
  961. a721 1
  962. - (Objekt) StoreCString: (CString) data
  963. d734 1
  964. a734 1
  965. - (Objekt) StoreInteger: (Integer) data
  966. d746 3
  967. d750 1
  968. a750 1
  969. - (Objekt) StoreMyError: (Integer) data
  970. d752 4
  971. a755 1
  972.     return [self PutInteger: data Into: MYERROR_RESULT];
  973. d766 1
  974. a766 1
  975. - (Objekt) StoreObject: (Objekt) data
  976. d779 1
  977. a779 1
  978. - (Objekt) StorePointer: (Pointer) data
  979. d792 1
  980. a792 1
  981. - (Objekt) StorePositiveInteger: (PositiveInteger) data
  982. @
  983.